﻿using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace xEditor.UI
{
    public class Toolbar : ToolStrip
    {
        #region Member Variables
        #endregion

        #region Properties
        #endregion

        #region Constructors

        public Toolbar()
        {
            Renderer = new TSRenderer();
            GripStyle = ToolStripGripStyle.Hidden;
        }

        #endregion

        #region Functions
        #endregion

        private class TSRenderer : ToolStripRenderer
        {
            protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
            {
                base.OnRenderButtonBackground(e);

                Rectangle borders = e.Item.ContentRectangle;
                borders.Width--;
                borders.Height--;
    
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(45, 45, 45)), borders);
            }

            protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
            {
                if (((ToolStripButton)e.Item).Checked)
                    e.TextColor = Color.White;

                base.OnRenderItemText(e);
            }

            protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
            {
                Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);

                int x = bounds.Right / 2;
                int margin = 4;

                e.Graphics.DrawLine(new Pen(Color.FromArgb(44, 44, 44)), x, bounds.Top + margin, x, bounds.Bottom - margin);
            }
        }
    }
}
